// winling 摇摆序列 前面小雨0  后面大雨0 前面大雨0 后面就要小雨0
function wiling(arr) {
    if (arr.length < 2) return arr.length
    let pcount = arr[0] - arr[1]
    let count = pcount === 0 ? 1 : 2;
    for (let i = 2; i < arr.length; i++) {
        let ccount = arr[i - 1] - arr[i];
        console.log(pcount, ccount)
        if ((pcount >= 0 && ccount < 0) || (pcount <= 0 && ccount > 0)) {
            count++;
            pcount = ccount
        }
    }
    return count
}

console.log(wiling([1, 7, 8, 9, 2, 0]))